<link rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css"
      rel="external nofollow">
<div id="pad-wrapper" class="new-user">

    <div class="row-fluid header">
        <h3>添加优惠券</h3>
    </div>


    <div class="row-fluid form-wrapper">
        <!-- left column -->
        <div class="span9 with-sidebar">
            <div class="container">
                <form class="new_user_form form-horizontal" action="/coupons/deal-add" method="post" id="dataForm"
                      enctype="multipart/form-data">

                    <div class="field-box"></div>
                    <div class="control-group form-group span12">
                        <label class="control-label" for="title">优惠券名称:</label>
                        <div class="controls col-lg-5">
                            <input type="text" class="form-control" id="coupons_name" name="coupons_name" placeholder="请输入优惠券名称"/>
                        </div>
                    </div>

                    <div class="control-group form-group span12">
                        <label class="control-label" for="title">优惠券类型:</label>
                        <div class="controls col-lg-5">
                            <label class="radio-inline">
                                <input type="radio" name="coupons_type" checked value="1"> 红包
                            </label>

                            <label class="radio-inline" style="display: inline-block">
                                <input type="radio" name="coupons_type" id="coupons_type" value="2"> 满减
                            </label>
                        </div>
                    </div>

                    <div class="control-group form-group span12" id="coupons_type_2" style="display: none;">
                        <label class="control-label" for="title">满金额:</label>
                        <div class="controls col-lg-5">
                            <input type="text" class="form-control" id="coupons_full_money" name="coupons_full_money" placeholder="请输入满金额"/>
                        </div>
                    </div>

                    <div class="control-group form-group span12" id="coupons_type_1">
                        <label class="control-label" for="title">优惠金额:</label>
                        <div class="controls col-lg-5">
                            <input type="text" class="form-control" id="coupons_money" name="coupons_money" placeholder="请输入优惠金额" onchange="if(this.value!=Math.floor(this.value)){alert('优惠金额只能为整数');this.value=Math.floor(this.value)}"/>
                        </div>
                    </div>

                    <div class="control-group form-group span12">
                        <label class="control-label" for="title">发放方式:</label>
                        <div class="controls col-lg-5">
                            <label class="radio-inline">
                                <input type="radio" name="coupons_release_type" checked id="coupons_release_type" value="1"> 代言申请发放
                            </label>

                            <!--<label class="radio-inline" >
                                <input type="radio" name="coupons_release_type" id="coupons_release_type" value="2"> 系统发放
                            </label>

                            <label class="radio-inline" >
                                <input type="radio" name="coupons_release_type" id="coupons_release_type" value="3"> 自动领取
                            </label>-->
                        </div>
                    </div>


                    <div class="control-group form-group span12">
                        <label class="control-label" for="title">限领次数:</label>
                        <div class="controls col-lg-5">
                            <input type="text" class="form-control" id="coupons_limit_number" value="1" name="coupons_limit_number" />
                        </div>
                    </div>

                    <div class="control-group form-group span12">
                        <label class="control-label" for="title">使用范围:</label>
                        <div class="controls col-lg-5">
                            <label class="radio-inline">
                                <input type="radio" name="coupons_use_target"  checked  value="1"> 单品
                            </label>

                            <!--<label class="radio-inline">
                                <input type="radio" name="coupons_use_target" value="2"> 产品组
                            </label>

                            <label class="radio-inline">
                                <input type="radio" name="coupons_use_target"  value="3"> 全场
                            </label>-->
                        </div>
                    </div>


                    <div class="control-group form-group span12" id="product_id">
                        <label class="control-label" for="product_id">选择产品:</label>
                        <div class="controls  col-lg-5">
                            <select  name="product_id" >
                                <option>请选择产品</option>
                                <?php foreach ($product_list as $v):?>
                                    <option value="<?=  $v['product_id']?>"><?= $v['product_name']?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                    </div>

                    <!--<div class="control-group form-group span12" id="product_group_id" style="display: none;">
                        <label class="control-label" for="teacher">选择产品组:</label>
                        <div class="controls  col-lg-5">
                            <select  name="product_group_id" >
                                <option>暂无数据</option>
                            </select>
                        </div>
                    </div>-->



                    <div class="control-group form-group span12">
                        <label class="control-label" for="link">发放有效时间:</label>
                        <div class="controls col-lg-5">
                            <input type="text" name="release_start_time" id="release_start_time"
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate"/>
                                到
                            <input type="text" name="release_end_time" id="release_end_time"
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate"/>

                        </div>
                    </div>



                    <div class="control-group form-group span12">
                        <label class="control-label" for="link">使用有效时间:</label>
                        <div class="controls col-lg-5">
                            <input type="text" name="use_start_time" id="use_start_time"
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate"/>
                            到
                            <input type="text" name="use_end_time" id="use_end_time"
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate"/>

                        </div>
                    </div>


                    <div class="span12 field-box"></div>
                    <div class="control-group form-group span12 actions">
                        <label class="control-label" for="" class="control-label"></label>
                        <div class="controls col-lg-5">
                            <input type="submit" class="btn-glow primary" value="提交"/>
                            <input type="reset" class="btn-glow primary" value="取消"/>
                        </div>
                    </div>


                </form>
            </div>
        </div>


        <!-- side right column -->
        <div class="span3 form-sidebar pull-right"></div>
    </div>
</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
<script type="text/JavaScript" src="/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
    //优惠券的使用范围 1：单品 2：产品组 3：全场 ,默认是1
    var coupons_use_target=1
    //点击选择优惠券的使用范围
    var selectTarget={
        //获取选择值
        get_checked_radio_value:function ($obj) {
            coupons_use_target=$obj.val();
            this.event_trigger(coupons_use_target);
        },
        //触发事件
        event_trigger:function ($type) {
            switch ($type){
                case '2':
                    $('#product_id').hide();
                    $('#product_group_id').show();
                    break;
                case '3':
                    $('#product_id').hide();
                    $('#product_group_id').hide();
                    break;
                case '1':
                    $('#product_id').show();
                    $('#product_group_id').hide();
                    break;
            }
        }
    }

    //点击使用范围按钮
    $(':radio[name=coupons_use_target]').change(function () {
        selectTarget.get_checked_radio_value($(this));
    });
    //点击红包或者满减
    $('input[name=coupons_type]').change(function () {
        var self_value=$(this).val();
        if(self_value==1){
            $('#coupons_type_2').hide();
            $('#coupons_type_1').show();
        }else if(self_value==2){
            $('#coupons_type_2').show();
            $('#coupons_type_1').show();
        }
    });



    //表单提交
    $('form').submit(function () {
        $(':submit').attr('disabled','disabled');
        $.post($(this).attr('action'),$('form').serialize(),function ($result) {
            alert($result.msg);
            if($result.status){
               window.location.href=$result.url;
            }else{
                $(':submit').removeAttr('disabled');
            }
        },'json');
        return false;
    });

</script>
    